package com.wholesale;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.wholesale.beans.GoodsDescribe;

public class GoodsDescLayout extends LinearLayout implements OnClickListener {
	private ViewFlipper viewFlipper;
	private Context context;
	private View baseView;
	private Button leftButton;
	private Button rightButton;
	private TextView headView;
	private WebView webView;
	final String mimeType = "text/html";  
	 
	final String encoding = "utf-8";

	// 构造函数
	public GoodsDescLayout(Context context, final ViewFlipper viewFlipper,
			GoodsDescribe goodsDesc) {
		super(context);
		this.viewFlipper = viewFlipper;
		this.context = context;
		// 加载需要的属性，加载方法一的子Layout
		baseView = ((Activity) getContext()).getLayoutInflater().inflate(
				R.layout.goodsdetaildesc, this);
		leftButton = (Button) baseView.findViewById(R.id.leftBtn);
		leftButton.setText("Back");
		leftButton.setOnClickListener(this);
		rightButton = (Button) baseView.findViewById(R.id.rightBtn);
		rightButton.setVisibility(View.INVISIBLE);
		rightButton.setOnClickListener(this);
		headView = (TextView) baseView.findViewById(R.id.title);
		headView.setText("Goods Desc");
		webView = (WebView) baseView.findViewById(R.id.webView);
		try {
			if(goodsDesc.getTable() != null && !goodsDesc.getTable().equals("")){
				 webView.loadData(URLEncoder.encode(goodsDesc.getTable(), encoding).replaceAll("\\+",
				 " "), mimeType, encoding);
			}
		} catch (UnsupportedEncodingException e) {
		}
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.leftBtn:
			viewFlipper.showPrevious();
			viewFlipper.removeView(this);
			break;
		case R.id.rightBtn:

			break;
		default:
			break;
		}

	}
}
